How to restrict Drupal commerce Shipping only for two provinces
If you are using the Address Field module, you definitely have Madrid and Guadalajara as options. Thereafter, you need to use rules and add conditions. I'm not sure how your shipping works but I would use the Flat Rate module to create components, such as 0-5km, which costs a set amount. Create a flat rate, give it a name: perhaps 0-5 km, and a price then add conditions. Select "Order address component comparison". Province will be available. Your operator is "equals" and then you add your values, Madrid and Guadalajara. 

Here is a screenshot of a rule that restricts shipping costs being applied to a certain country, within weight parameters and restricts it to a particular product but it is possible to select a province instead of a country


Here is a screenshot of the components, I selected province here to show that it is available