Time finally ran out for Hostess Brands on Wednesday, as a bankruptcy judge gave preliminary approval for the company to shut down after 82 years in business.

A last-ditch attempt to mediate a pay-and-benefits dispute between the company and its Bakery Workers union failed.

The decision by Judge Robert Drain sets the stage for the company to start selling its assets -- including its bakeries, brands and recipes.

"Sadly, the parties were not able to come to an agreement," said Drain. "It's a free country. People are free not to agree."

Hostess, maker of such beloved products as Twinkies, Wonder Bread and Drake's snacks, announced Tuesday night the mediation efforts had failed to produce a deal.

About 15,000 of the company's current 18,500 employees will likely be terminated in the coming days. The company said in court it needs about 3,200 employees to stay on for various periods of time to wind down the company.

The company's operations have been closed since last Friday. Hostess' CEO and attorneys previously said that reaching a deal to restart the company's network of 33 bakeries and 565 distribution centers would be difficult due to the financial damage done by the strike that started Nov. 9.

But Hostess' investment bankers testified that there have been dozens of inquiries about a possible purchase of various brands and even some facilities. Joshua Scherer, of Perella Weinberg, told the court that some of the interested parties had inquired about hiring back some workers.

"It's a once in a lifetime opportunity for [Hostess'] competitors," he testified.

Related: The day the Twinkies died: What the Web said

Hostess CEO Greg Rayburn told reporters after the hearing that the company would move as quickly as possible to sell the brands, although he would give no specific time frame for when the iconic products could be available to consumers once again.

"The longer we're off the shelves, the less value we're going to get," he said. He said it's difficult to handicap the chances that Hostess workers could be rehired by those who buy assets.

Asked by CNNMoney if the sale would be strictly to the highest bidder or whether the buyer's interest in hiring workers would be a consideration, Rayburn said "You have to try to do both."

On Monday, private equity firm Sun Capital Partners told Fortune that it wants to buy Hostess as a going concern. It would reopen the shuttered factories, and keep the Hostess workers and their unions. But it's not clear Sun Capital's offer would top those of other bidders who would simply produce the product with the bidders' existing facilities, leaving the Hostess workers out of luck.

Related: Twinkies hoarding begins

Drain scheduled another hearing for Nov. 29. At that time, he will consider Hostess' request for approval of $1.75 million in bonuses, ranging from $7,400 to $130,500, to be paid to 19 executives to oversee the liquidation of the company. Hostess said it needs to pay the bonuses to make sure key executives stay with the company through the end.

"The cessation of ... operations is not a simple matter of turning off the lights and shutting the doors," the company wrote in a court filing on Friday.

Unions at Hostess are on record opposing the bonus requests. The Justice Department's bankruptcy trustee in the case has also filed an objection to the bonus plan.

The Bakery Workers union has repeatedly said that mismanagement and the debt placed on the company by its current and past owners were the reasons for the company's failure, not the strike. It said its membership was overwhelmingly opposed to the wage and benefit concessions agreed to by other Hostess employees, including the majority of the 6,700 members of the Teamsters' union at Hostess.

Related: Hostess jobs - 'Great' to 'not worth saving'

The Teamsters issued a statement Tuesday saying the failure of mediation and the likely liquidation of the company was a tragic outcome. It did not comment on who it blamed for the shutdown.

A statement last week blamed poor management for the shutdown, but also appeared to also criticize the bakers' union without explicitly naming it, saying that "not all stakeholders were willing to be constructive."