Section 28. The said towns may contract with the department for the performance of the work authorized by section twenty-six; or, if the selectmen so request, the department may have the work done by such persons and in such manner as it may determine, in which event the towns shall pay their proportionate part of the expense when and as ordered by the department. The cost of any materials, machinery or tools purchased by the department for or on account of the work in any town shall be considered as a part of the expenditures in such town under section twenty-six; and such machinery or tools shall belong to the commonwealth.