Trains to Alberobello
Ferrovie del Sud Est have a train line between Bari and Taranto, with several stops on the way, including Alberobello and Castellana Grotta. This link is to the websites timetable (pdf-file).
The train runs frequently and almost hourly, but pay attention to this: Not on Sundays!! We went to the station of Alberobello and it was completely shot down, and there were no trains that day, only busses.
Getting to Alberobello
I went by car to Alberobello, and it's not that hard to find. Head south of Bari on S100 and then east (signposted) on S172. Just outside the tourist area you'll find lots of parking spaces, for which you have to pay though. I can't remember how much anymore, but I don't think it was that cheap.
You can also go by train to Alberobello. FSE trains leave Bari every hour (every 2 hr. on Sundays) heading to Alberobello. The trip takes about 1 3/4 hours and costs 6€ . To find the trulli, follow Via Mazzini, which turns into Via Garibaldi, until you reach Piazza del Popolo. Turn left on Largo Martellotta, which will take you to the edge of the popular tourist area.