DeMarre Carroll, right, defends against LeBron James on May 23, 2016 in Toronto. (Getty Images)

The Brooklyn Nets on Saturday got the news they expected, if also news they didn’t want to hear, when they were informed by the Washington Wizards that their offer sheet to small forward Otto Porter Jr. would be matched.

But it didn’t take long for Brooklyn to find a sufficient Plan B — or to show that there is at least one New York basketball team operating on a steady and true path forward.

Just hours after they learned Porter wouldn’t be a Net, Brooklyn agreed to a deal with Toronto, shipping backup center Justin Hamilton to the Raptors for small forward DeMarre Carroll, plus first- and second-round picks in the 2018 NBA draft.

Carroll is nowhere near the level of Porter, though Carroll could be Brooklyn’s starter next season at small forward, as Porter was supposed to be. After signing a four-year, $60 million deal as a free agent in 2015, Carroll has spent the past two years in Toronto battling injuries and has seen his stock plummet.

That has made the task of moving him a difficult one for Raptors General Manager Masai Ujiri, particularly as cap space around the league is quickly disappearing. And that’s why Sean Marks, his counterpart with the Nets, was able to get him to agree to a deal early Sunday morning when it won’t be able to be completed for several days.

(A quick aside: The deal won’t be completed for several days – likely Thursday – because the Wizards plan to maximize the amount of time necessary to clear Porter’s physical, keeping his $24.7 million starting salary on Brooklyn’s books for up to an additional 96 hours. While this could have left the Nets in a position where a deal they wanted to make couldn’t happen for lack of immediate cap space, it was wise of Marks to find a team that both needed to move on from a big salary, like Toronto with Carroll, and was willing to make a deal in a few days because it knows the money would eventually leave its books).

Porter staying in Washington meant a fourth straight time the Nets have swung and missed at a restricted free agent under Marks. Porter joined Tyler Johnson (Miami Heat), Allen Crabbe (Portland Trail Blazers) and Donatas Motiejunas (Houston Rockets) as players who agreed to become Nets only to return to their old teams, and Brooklyn has earned some jeers from some corners for continuing to pursue this path.

But while Marks hasn’t succeeded in going that route during his first 18 months on the job, it has allowed him to do something else with the cap space those failed offer sheets left behind: use it to gain future assets.

Over the past six months, the Nets have now swung three trades for essentially dead money — one with the Wizards for Andrew Nicholson, another with the Los Angeles Lakers and then this weekend’s move for Carroll. So what has the return from those trades been? Two first-round picks, a second-round pick and 2015 No. 2 overall pick D’Angelo Russell — the player the team hopes will become their point guard of the next decade.

That’s exactly the kind of thing desperately needed by a rebuilding team such as Brooklyn, which hasn’t controlled its first-round pick since 2014 because of the disastrous Paul Pierce-Kevin Garnett trade with the Boston Celtics the summer before. Even if the offer sheets haven’t worked out the way the Nets wanted, they still have been able to use that space to accomplish the same goal: acquiring as much youthful talent as possible.

The result is a roster now populated with interesting young players, from Russell to last year’s first-round pick, guard Caris LeVert, to this year’s first-round pick, center Jarrett Allen, to forward Rondae Hollis-Jefferson and guard Isaiah Whitehead. Brooklyn also has future cap space and, after next year’s draft, control of its future first-round picks.

So, despite the knocks the team has suffered in recent months – having the worst record (20-62) in the NBA last season, seeing its pick become the first overall selection in last month’s draft and go to Boston because of the Pierce-Garnett trade, and having Porter’s offer sheet become the latest one to come and go — there is a formula in place and a plan that is clearly paying off.

Then there is the other team in New York. Having finally made the necessary decision to send Phil Jackson packing late last month, the Knicks proved they didn’t need Jackson to continue to make mistakes when they handed out the worst contract of the summer for a second straight year, signing Tim Hardaway Jr. to a four-year, $71 million offer sheet. The deal was so exorbitant that the only question was how long the Knicks would have to wait for Hardaway’s prior team, the Atlanta Hawks, to notify them that they would let him leave.

It was the latest Knicks move that baffled on every level. The Knicks should be following a path similar to the Nets, trying to accumulate young assets to play alongside budding star Kristaps Porzingis. Instead, they’ll have well over $40 million per season the next three years tied up with Joakim Noah, Courtney Lee and Hardaway — none of whom are likely to even start on a good team. Plus, Lee and Hardaway play the same position.

And that doesn’t even begin to take into effect the distrust that has formed between Porzingis and the organization over the past few months.

As ESPN reported early Sunday morning, the Knicks could go a long way toward changing things by hiring their own competent front-office head if they manage to get over the finish line with former Cleveland Cavaliers general manager David Griffin, who is more than capable of overseeing a rebuild. But whether with Griffin, current top basketball executive Steve Mills or someone else, the Knicks would be wise to look at what Brooklyn is doing for an example of how a rebuild should be done.

The Porter news didn’t go Brooklyn’s way on Saturday night. But with a quick pivot to a Plan B — even if it’ll take a few days for it to officially happen — the Nets showed why there is still reason for optimism around a team that, after taking so many lumps for so long, is sticking to a plan that has them on the right path and is beginning to bear fruit.