What is the best way to go to Matera from Bari?
no train take Flixbus
https://shop.flixbus.com/
Trains are run by a separate local company, Ferrovie Appulo Lucane. Their main station is next to the main Bari Centrale station, on a higher level.
http://ferrovieappulolucane.it
(the search engine is somewhat confusing as you have to tick "treno" to have train timetables)
and if you thought the search engine was confsuing wait till you see the timetable posters!
http://ferrovieappulolucane.it/wp-content/uploads/2013/07/ORTRENI11-12-2016-1.pdf
There is train service, as described above, very inexpensive and frequent. Takes about an hour, perhaps a bit more. You can just walk up and buy a ticket at the train station.
Matera has at least two train stations; if someone is picking you up, Matera Sud is closer to the Sassi. There is no taxi standing by here, but you can call one. The central station has local bus service, or you can call a taxi.