Dynamics and control of antibiotic resistance in structured metapopulations