How do you formulate a distance constraint and a budget constraint? Everybody knows about budget constraints and how they are represented:

but what if I want to represent a distance constrain from the shop you buy the goods?  How can I build that?
Because you are talking about constraints, it appears you do not consider the case of inserting such &quot;access costs&quot; (because this is what they are) in the utility function. It implies that they do not create disutility directly, only direct or indirect monetary costs.
Let $d$ be the distance in some units. Let $C_d = c_dd$ be a linear (for simplicity) distance cost function,  where $c_d$ is the average cost per unit of distance. This cost may include fuel consumed, or opportunity costs of spending the time to go to the shop. It is realistic to also postulate the existence of a strictly non-zero minimum distance, $d_{min}$, because the shops are not inside your house.
Your budget constraint now looks like (the undefined symbols have the usual meaning)
$$\sum p_ix_i + c_dd \leq I,$$
while you also have the additional constraint $ d \geq d_{min}$. So the Lagrangian is here
$$U(\mathbf x) + \lambda \left(I-\sum p_ix_i - c_dd\right) + \mu(d- d_{min}),$$
with $\lambda, \mu$ being the non-negative Karush-Kuhn-Tucker multipliers. Your optimization problem involves maximizing the Lagrangian with respect to the $x_i$s and with respect to $d$.
One could specify reasonably a convex non-linear distance cost function. Finally, one could include $d$ in the utility function as generating directly disutility.
I guess you can take it from here.
Just note that with the formulation as above, you should obtain that at the solution, $\mu^* &gt;0$ meaning that the constraint will be binding and so you will always choose to go to the nearest shop... which aligns, at least in this case, with intuition (don't start thinking about shop/product differentiation, that would be a whole different situation).