The initial hit is always the hardest, it stabilizes after the 3rd year. This goes for most vehicles on the market, and the RAM has historically had high resale as due most full size trucks compared to other classes. But not first year resale. Only high demand hard to get vehicles have high resale on first year, which the RAM is not one of those.
You have a couple of things going against you. One is trying to sell within a few months of purchase, two is the discount for new trucks will hurt your resale. Why would anyone want your 7 month old truck with almost $10,000 miles for nearly the same price for a new one?
Also, the dealership needs to make money. They are offering you $31,000 at CarMax, who will then try to sell it at $34,000.
Your best bet is to avoid the dealership and sell privately, you will make $2,000 - $3,000 more that way. However, the best move is wait 2-3 years and you will be in the black and ready to trade with equity.