You need some structure or Collection that represents the "state" of your bag. A part of the state needs to identify all the items in the bag at a given point in time and their sum weight and sum cost. You start out with an initial state for an empty bag.
You enter your recursive method with a state.
You look to see what you can add to the state that will not exceed the weight.
If that state has been tried before, return null.
If it is the exact weight, see of the cost is less than the last state that had the exact weight, then return the state.
If it is less than the weight, take the new state and pass it to the next call to the method.
If it is greater than the weight, return null.
The answer will be returned as you unwind the recursion back to the original call.
There are some subtleties not mentioned here, like, "almost" exact weight, but this is the general gist.