Instead of $\{0,1\}^n$, you may take as your code space a subset $S\subseteq\{0,1\}^n$ of diameter $D$. This will guarantee that, whatever code you define in $S$, its codewords will be at distance $\leq\! D$.
The usual Gilbert-Varshamov bound states that the cardinality of an optimal code of minimum distance $d$ in $\{0,1\}^n$ is lower-bounded by $$\frac{2^n}{B_n(d-1)},$$ where $$B_n(r)=\sum_{t=0}^r \binom{n}{t}$$ is the cardinality of (any) ball of radius $r$ in the Hamming space $\{0,1\}^n$. Note that, in your restricted space $S$, not all balls have the same cardinality, so it is not obvious how to directly apply the GV bound. However, there is a generalization of the GV bound stating that the cardinality of an optimal code in $S$ is lower-bounded by $$\frac{|S|}{\overline{B_n(d-1)}},$$ where $\overline{B_n(r)}$ is the average cardinality of a ball of radius $r$ in $S$. Now the problem is down to estimating the latter quantity, which in some cases can be done exactly (see for example the works citing the above-mentioned paper by Gu and Fuja, some of them quite recent).
Note: To maximize the code size, you may want to take for $S$ the largest possible set of diameter $D$ (i.e., a maximal anticode), which is a ball of radius $D/2$ for even $D$, or a union of two balls of radius $\lfloor D/2 \rfloor$ centered at neighboring points for odd $D$. In this case, assuming for simplicity that $D$ is even, you would have $$|S|=\sum_{t=0}^{D/2} \binom{n}{t}.$$