How to programatically disable shipping method in magento

I am using two shipping method Free shipping and flat rate shipping .
Here is two condition when a user try to buy “apple” from state “abc” then flat rate shipping available for this user.and another user try to buy same product “apple” from state “xyz” then free shipping is available for this user.
I know it can be done by using observer but unable to find any exact solution please help me thanks.