(CNN) Canada will take back tons of garbage shipped to the Philippines years ago, in a major victory for President Rodrigo Duterte in a diplomatic row which saw him recall his ambassador to Ottawa .

The Canadian government will cover the full cost of the operation and the garbage will be brought back before the end of June, Environment Minister Catherine McKenna said in a statement published Wednesday. The government has hired a private Canadian shipping company to handle the operation.

Canada had already agreed to take back the trash but missed a May 15 deadline set by Duterte, prompting him to recall the envoy.

McKenna's announcement came soon after Duterte's spokesman Salvador Panelo announced that local officials had been ordered to find a private shipping company to transport the rubbish back to Canada.

"If Canada will not accept their trash, we will leave the same within its territorial waters or 12 nautical miles out to sea from the baseline of any of their country's shores," Panelo said.

Duterte, known for his brash and outspoken style, had said he was prepared to " declare war" on Canada over the issue.

Philippines officials say the containers of trash, which arrived in 2013 and 2014, were wrongly labeled as containing recyclable plastics . Upon inspection they were found to be filled with waste including diapers, newspapers and water bottles.

According to CNN Philippines, 103 containers holding 2,450 tons of trash were shipped to the Philippines by a private Canada-based company. Most of it has remained in the Philippine ports of Manila and Subic ever since, despite a 2016 court ruling ordering the firm, Chronic Inc, to take the garbage back.

Last week, Canadian Foreign Minister Chrystia Freeland spoke to her Filipino counterpart about the row.

"As I mentioned to their Foreign Secretary last week, we are committed to resolving this issue as quickly as possible. Today is an essential step forward in accomplishing that," Freeland said in the statement on Wednesday.