I haven't been to Bari. I based in Lecce (farther south) and used van transportation offered by the Lecce tourist office to get to smaller towns. There is some public transportation in the area, but it is rather limited.
To see what might be available you can start with Rome2Rio.com, but do not trust the fares, travel times or frequencies it displays. They are the product of a very creative brain or a bad search function. Instead, you need to keep clicking through the website until you find the name of the bus company offering the service; usually there's a link provided to the appropriate website. Get your schedule/fare information from the bus company's website.
Alternatively, you can Google something like bus Alberobello to Martina Franca and check out the likeliest-looking links. This may be easier than dealing with Rome2Rio, but Rome2Rio can be helpful in pointing out where you can make a transfer to get where you want to go.
For train service check Trenitalia.com. Be sure to adjust the departure time to fit your needs. I see that Trenitalia shows some buses between at least 3 different stations in Bari and Alberobello. I think there are very few trains going to Alberobello. I imagine you'll need to take some sort of bus (or taxi) from the Bari airport to one of the downtown train stations to pick up a bus to Alberobello. Note that it's possible to encounter sluggish ticket lines at Italian rail stations. It's definitely worth trying the ticket-vending machines; English should be available. I can't promise your US credit card will work in the machines, but it is definitely worth trying.