Section 147. Where a railroad and a public way or travelled place cross at the same level, the department, after notice to the interested parties and a hearing, shall order the crossing to be protected by gates, flagman, flashing light signals or such other protective measures as the department determines the better security of human life or the convenience of public travel requires, and the railroad corporation operating the railroad over the crossing shall install, maintain and operate the protection in compliance with such order. The cost of installing, maintaining and operating such protection shall be apportioned by the department between the railroad passing over the crossing, the town or city in which the highway is located, the county, if the highway is a county road, or the commonwealth, if the highway is a state highway, and any land in a limited and determinable area receiving benefit or advantage, other than the general advantage to the community, from such protection, and in accordance with the relative benefit to be derived by each from such protection, giving due consideration to whether the railroad or the highway was first constructed, to the nature and volume of highway travel, to the number of trains operated by the railroad over the crossing, and to all other relevant facts and circumstances. No part of the cost of installing, maintaining or operating such protection shall be apportioned or charged under this section against any city or town in the fourteen cities and towns or the sixty-four cities and towns, both as defined in section one of chapter one hundred and sixty-one A, with respect to any crossing of a railroad or railroad corporation operated under any contract with the Massachusetts Bay Transportation Authority. Any costs apportioned against land under this section shall be levied, assessed and collected in the same manner as a betterment under chapter eighty, so far as applicable.