When we restrict ourselves to an \( M \)-scheme basis, we could choose two paths. The first is simplest (and simplest is often best, at least in the first draft of a code): generate all possible Slater determinants, and then extract from this initial list a list of those Slater determinants with a given \( M \). (You will need to write a short function or routine that computes \( M \) for any given occupation.)
Alternately, and not too difficult, is to run the odometer routine twice: each time, as as a Slater determinant is calculated, compute \( M \), but do not store the Slater determinants except the current one. You can then count up the number of Slater determinants with a chosen \( M \). Then allocated storage for the Slater determinants, and run the odometer algorithm again, this time storing Slater determinants with the desired \( M \) (this can be done with a simple logical flag).