For the table's side, you'd have to provide Box2D a table size minus the radius of the cue ball on each side, then do a line cast. If the line hits the wall, you know that ball would hit the side.

For ball to ball, it's a bit trickier, since balls can hit a different angles. Not sure what options Box2D provides here, but circle to circle collision check is really simple. If the distance of points is smaller than the combined radi of the two circles, you have a collision.