Section 22M. In addition to all other rates, charges and fees it may otherwise be authorized to impose and collect any utility shall impose and collect as a capital contribution towards the cost of construction a surcharge of two per cent on its total billing to each customer located in a city or town which has in force and effect an ordinance or by-law adopted in accordance with section 22D. However, a distribution company, as defined in section 1 of chapter 164, shall impose and collect a surcharge of 7 per cent of retail delivery revenues, plus interest at the rate set by the department, for customer security deposits except in a city or town that before the effective date of this section has enacted an ordinance or by-law under section 22D establishing a 2 per cent surcharge or where construction is in progress or already completed, unless the city or town otherwise agrees to the 7 per cent surcharge by adopting an ordinance or by-law under said section 22D. A surcharge under this section shall apply only if the distribution company is not in violation of the ordinance or by-law and if the ordinance or by-law has been in effect for a period of at least 1 year.